<template>
  <breadcrumb :levelList="levelList" />
  <el-card class="card">
    <el-form :inline="true" :model="formData" class="demo-form-inline">
      <el-form-item label="数据表名称">
        <el-input v-model="tableName" placeholder="数据表名称" clearable />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="genCode()">更新</el-button>
      </el-form-item>
    </el-form>
    <h3>代码模板</h3>
    <el-tabs v-model="router" class="demo-tabs" >
      <el-tab-pane label="路由" name="router">
        <el-input :rows="30" type="textarea"  v-model="result['router']"/>
      </el-tab-pane>
      <el-tab-pane label="entity" name="entity">
        <el-input :rows="30" type="textarea" v-model="result['entity']" />
      </el-tab-pane>
      <el-tab-pane label="schema" name="schema">
        <el-input :rows="30" type="textarea" v-model="result['schema']" />
      </el-tab-pane>
      <el-tab-pane label="model" name="model">
        <el-input :rows="30" type="textarea" v-model="result['model']" />
      </el-tab-pane>
      <el-tab-pane label="controller" name="controller">
        <el-input :rows="30" type="textarea" v-model="result['controller']" />
      </el-tab-pane>
      <el-tab-pane label="api.js" name="api.js">
        <el-input :rows="30" type="textarea" v-model="result['api.js']" />
      </el-tab-pane>
      <el-tab-pane label="vue" name="vue">
        <el-input :rows="30" type="textarea" v-model="result['vue']" />
      </el-tab-pane>
    </el-tabs>
  </el-card>
</template>

<script setup>
import { reactive, ref } from 'vue'
import service from '@/utils/request'
import breadcrumb from '@/views/common/breadcrumb.vue'
const levelList = ['首页','开发辅助','代码生成']

const tableName = ref('xxx')
const router = ref('router')

const result = reactive({
  'router':'',
  'entity':'',
  'schema':'',
  'model':'',
  'controller':'',
  'api.js':'',
  'vue':''
})

const genCode = ()=>{
  service.get("/tool/gen/code?table_name="+tableName.value).then(res=>{
    if(res.code!=200)
      return;
    result['router']     = res.data['router']    ;
    result['entity']     = res.data['entity']    ;
    result['schema']     = res.data['schema']    ;
    result['model']      = res.data['model']     ;
    result['controller'] = res.data['controller'];
    result['api.js']     = res.data['api.js']    ;
    result['vue']        = res.data['vue']       ;
  })
}

genCode();
</script>

<style scoped>

</style>